/**
 * @file gameauthprogresswidget.cpp
 * @brief 游戏认证进度页面组件实现文件
 *
 * 实现游戏认证进度页面的所有功能，包括：
 * - UI界面的创建和布局管理
 * - 认证步骤的进度显示
 * - 动画效果和视觉反馈
 * - 用户交互和事件处理
 */

#include "../include/gameauthprogresswidget.h"
#include "../include/config.h"
#include <QDebug>               // 调试输出
#include <QShowEvent>           // 显示事件
#include <QHideEvent>           // 隐藏事件
#include <QEasingCurve>         // 缓动曲线
#include <QStyle>               // QStyle类定义
#include <QDateTime>            // 时间戳生成

/**
 * @brief GameAuthProgressWidget构造函数
 * @param parent 父窗口部件指针
 */
GameAuthProgressWidget::GameAuthProgressWidget(QWidget *parent)
    : QWidget(parent)
    , m_mainLayout(nullptr)
    , m_currentStep(Connecting)
    , m_isAuthenticating(false)
    , m_animationTimer(new QTimer(this))
    , m_fadeAnimation(nullptr)
    , m_opacityEffect(nullptr)
    , m_animationFrame(0)
    
    // === 主题颜色配置（与MainWindow保持一致） ===
    , m_primaryColor("#4A90E2")      // 主色调：蓝色系
    , m_secondaryColor("#7ED321")    // 辅助色：绿色系 
    , m_backgroundColor("#2C3E50")   // 背景色：深蓝灰色
    , m_textColor("#ECF0F1")         // 文字色：浅灰白色
    , m_errorColor("#E74C3C")        // 错误色：红色系
    , m_successColor("#27AE60")      // 成功色：绿色系
    , m_warningColor("#F39C12")      // 警告色：橙色系
{
    // === 设置窗口属性 ===
    setWindowTitle("游戏认证");
    setMinimumSize(600, 400);
    resize(700, 500);
    
    // === 初始化步骤配置 ===
    m_stepTitles = {
        "连接网关",
        "权限认证", 
        "获取令牌",
        "连接游戏",
        "认证完成"
    };
    
    m_stepIconTexts = {
        "🌐",  // 连接网关
        "🔐",  // 权限认证
        "🎫",  // 获取令牌
        "🎮",  // 连接游戏
        "✅"   // 认证完成
    };
    
    // === 设置UI界面 ===
    setupUI();
    
    // === 应用统一主题 ===
    applyUnifiedTheme();
    
    // === 设置动画定时器 ===
    m_animationTimer->setInterval(200); // 200ms间隔
    connect(m_animationTimer, &QTimer::timeout, this, &GameAuthProgressWidget::onAnimationTimer);
    
    qDebug() << "GameAuthProgressWidget initialized";
}

/**
 * @brief GameAuthProgressWidget析构函数
 */
GameAuthProgressWidget::~GameAuthProgressWidget()
{
    stopLoadingAnimation();
    qDebug() << "GameAuthProgressWidget destroyed";
}

/**
 * @brief 开始认证流程
 * @param serverInfo 目标服务器信息
 * @param gameType 游戏类型
 */
void GameAuthProgressWidget::startAuthentication(const GameService::GameServer &serverInfo, const QString &gameType)
{
    qDebug() << "GameAuthProgressWidget: Starting authentication for" << gameType << "server" << serverInfo.name;
    
    // === 保存认证信息 ===
    m_serverInfo = serverInfo;
    m_gameType = gameType;
    m_isAuthenticating = true;
    
    // === 重置状态 ===
    resetAuthentication();
    
    // === 更新标题信息 ===
    QString gameTypeIcon = gameType == "snake" ? "🐍" : 
                          gameType == "tetris" ? "🧩" : 
                          gameType == "puzzle" ? "🧠" : "🎮";
    
    m_titleLabel->setText(QString("%1 游戏认证").arg(gameTypeIcon));
    m_subtitleLabel->setText(QString("正在连接到 %1 服务器...").arg(serverInfo.name));
    
    // === 开始认证流程 ===
    updateAuthStep(Connecting, "正在连接API网关...");
    startLoadingAnimation();
    
    // === 显示操作按钮 ===
    m_cancelButton->setVisible(true);
    m_retryButton->setVisible(false);
}

/**
 * @brief 取消认证流程
 */
void GameAuthProgressWidget::cancelAuthentication()
{
    qDebug() << "GameAuthProgressWidget: Authentication cancelled by user";
    
    m_isAuthenticating = false;
    stopLoadingAnimation();
    
    emit authenticationCancelled();
}

/**
 * @brief 重置认证状态
 */
void GameAuthProgressWidget::resetAuthentication()
{
    // === 重置进度 ===
    m_currentStep = Connecting;
    m_progressBar->setValue(0);
    m_statusLabel->setText("准备开始认证...");
    m_detailLabel->setText("");
    
    // === 重置步骤指示器 ===
    for (int i = 0; i < m_stepIndicators.size(); ++i) {
        setStepCompleted(i, false);
        setStepActive(i, false);
        setStepError(i, false);
    }
    
    // === 设置第一步为活动状态 ===
    if (!m_stepIndicators.isEmpty()) {
        setStepActive(0, true);
    }
    
    // === 重置按钮状态 ===
    m_cancelButton->setEnabled(true);
    m_retryButton->setVisible(false);
}

/**
 * @brief 更新认证步骤
 * @param step 当前步骤
 * @param message 状态消息
 */
void GameAuthProgressWidget::updateAuthStep(AuthStep step, const QString &message)
{
    qDebug() << "GameAuthProgressWidget: Updating step to" << static_cast<int>(step) << "with message:" << message;
    
    AuthStep previousStep = m_currentStep;
    m_currentStep = step;
    
    // === 更新进度条 ===
    int progress = 0;
    switch (step) {
        case Connecting:     progress = 10; break;
        case Authenticating: progress = 30; break;
        case GettingToken:   progress = 60; break;
        case ConnectingGame: progress = 80; break;
        case Completed:      progress = 100; break;
        case Failed:         progress = 0; break;
    }
    setAuthProgress(progress);
    
    // === 更新状态信息 ===
    if (!message.isEmpty()) {
        m_statusLabel->setText(message);
    }
    
    // === 更新步骤指示器 ===
    updateStepIndicator(step);
    
    // === 播放步骤转换动画 ===
    if (step != previousStep && step != Failed) {
        animateStepTransition(step);
    }
    
    // === 处理特殊状态 ===
    if (step == Completed) {
        stopLoadingAnimation();
        m_statusLabel->setText("🎉 认证成功！正在进入游戏...");
        m_detailLabel->setText("即将为您打开游戏界面");
        m_cancelButton->setVisible(false);
    } else if (step == Failed) {
        stopLoadingAnimation();
        m_cancelButton->setText("返回");
        m_retryButton->setVisible(true);
    }
}

/**
 * @brief 设置认证进度
 * @param progress 进度百分比 (0-100)
 */
void GameAuthProgressWidget::setAuthProgress(int progress)
{
    m_progressBar->setValue(progress);
    
    // === 更新详细信息 ===
    QString detail;
    if (progress < 30) {
        detail = "正在建立安全连接...";
    } else if (progress < 60) {
        detail = "验证游戏权限...";
    } else if (progress < 80) {
        detail = "生成会话令牌...";
    } else if (progress < 100) {
        detail = "准备游戏环境...";
    } else {
        detail = "认证流程已完成！";
    }
    
    m_detailLabel->setText(detail);
}

/**
 * @brief 显示认证错误
 * @param error 错误信息
 */
void GameAuthProgressWidget::showAuthError(const QString &error)
{
    qDebug() << "GameAuthProgressWidget: Authentication error:" << error;
    
    updateAuthStep(Failed);
    m_statusLabel->setText("❌ 认证失败");
    m_detailLabel->setText(error);
    
    // === 设置当前步骤为错误状态 ===
    if (static_cast<int>(m_currentStep) < m_stepIndicators.size()) {
        setStepError(static_cast<int>(m_currentStep), true);
    }
    
    emit authenticationFailed(error);
}

/**
 * @brief 显示认证成功
 * @param result 认证结果
 */
void GameAuthProgressWidget::showAuthSuccess(const GameService::GameLoginResult &result)
{
    qDebug() << "GameAuthProgressWidget: Authentication successful";
    
    updateAuthStep(Completed);
    
    // === 显示成功信息 ===
    QString successMessage = QString("成功连接到 %1").arg(result.serverInfo.name);
    m_statusLabel->setText("✅ " + successMessage);
    m_detailLabel->setText("会话令牌已获取，正在进入游戏...");
    
    emit authenticationCompleted(result);
}

/**
 * @brief 显示事件处理
 * @param event 显示事件
 */
void GameAuthProgressWidget::showEvent(QShowEvent *event)
{
    QWidget::showEvent(event);
    
    // === 创建淡入动画 ===
    if (!m_opacityEffect) {
        m_opacityEffect = new QGraphicsOpacityEffect(this);
        setGraphicsEffect(m_opacityEffect);
    }
    
    if (!m_fadeAnimation) {
        m_fadeAnimation = new QPropertyAnimation(m_opacityEffect, "opacity", this);
        m_fadeAnimation->setDuration(300);
        m_fadeAnimation->setEasingCurve(QEasingCurve::OutCubic);
    }
    
    m_fadeAnimation->setStartValue(0.0);
    m_fadeAnimation->setEndValue(1.0);
    m_fadeAnimation->start();
}

/**
 * @brief 隐藏事件处理
 * @param event 隐藏事件
 */
void GameAuthProgressWidget::hideEvent(QHideEvent *event)
{
    stopLoadingAnimation();
    QWidget::hideEvent(event);
}

/**
 * @brief 取消按钮点击槽
 */
void GameAuthProgressWidget::onCancelClicked()
{
    if (m_isAuthenticating) {
        cancelAuthentication();
    } else {
        // 如果不在认证中，表示是"返回"按钮
        emit authenticationCancelled();
    }
}

/**
 * @brief 重试按钮点击槽
 */
void GameAuthProgressWidget::onRetryClicked()
{
    qDebug() << "GameAuthProgressWidget: Retrying authentication";
    
    emit retryAuthentication();
    
    // === 重新开始认证 ===
    if (!m_serverInfo.serverId.isEmpty()) {
        startAuthentication(m_serverInfo, m_gameType);
    }
}

/**
 * @brief 动画定时器槽
 */
void GameAuthProgressWidget::onAnimationTimer()
{
    m_animationFrame = (m_animationFrame + 1) % 4;
    
    // === 更新加载动画 ===
    QString dots;
    for (int i = 0; i <= m_animationFrame; ++i) {
        dots += "⬤";
    }
    for (int i = m_animationFrame + 1; i < 4; ++i) {
        dots += "⬜";
    }
    
    // === 更新当前活动步骤的图标 ===
    if (static_cast<int>(m_currentStep) < m_stepIcons.size() && 
        static_cast<int>(m_currentStep) < m_stepIndicators.size()) {
        QLabel *iconLabel = m_stepIcons[static_cast<int>(m_currentStep)];
        if (iconLabel && m_isAuthenticating) {
            iconLabel->setText(dots);
        }
    }
}

/**
 * @brief 设置UI界面
 */
void GameAuthProgressWidget::setupUI()
{
    m_mainLayout = new QVBoxLayout(this);
    m_mainLayout->setContentsMargins(40, 40, 40, 40);
    m_mainLayout->setSpacing(30);
    
    // === 设置头部区域 ===
    m_headerWidget = new QWidget();
    m_headerLayout = new QVBoxLayout(m_headerWidget);
    m_headerLayout->setContentsMargins(0, 0, 0, 0);
    m_headerLayout->setSpacing(10);
    
    m_titleLabel = new QLabel("🎮 游戏认证");
    m_titleLabel->setObjectName("authTitle");
    m_titleLabel->setAlignment(Qt::AlignCenter);
    
    m_subtitleLabel = new QLabel("正在准备连接...");
    m_subtitleLabel->setObjectName("authSubtitle");
    m_subtitleLabel->setAlignment(Qt::AlignCenter);
    
    m_headerLayout->addWidget(m_titleLabel);
    m_headerLayout->addWidget(m_subtitleLabel);
    m_mainLayout->addWidget(m_headerWidget);
    
    // === 设置步骤指示器 ===
    setupStepIndicators();
    
    // === 设置进度区域 ===
    setupProgressArea();
    
    // === 设置操作按钮 ===
    setupActionButtons();
    
    m_mainLayout->addStretch();
}

/**
 * @brief 设置步骤指示器
 */
void GameAuthProgressWidget::setupStepIndicators()
{
    m_stepsWidget = new QWidget();
    m_stepsLayout = new QHBoxLayout(m_stepsWidget);
    m_stepsLayout->setContentsMargins(20, 20, 20, 20);
    m_stepsLayout->setSpacing(0);
    
    for (int i = 0; i < m_stepTitles.size(); ++i) {
        // === 创建步骤容器 ===
        QWidget *stepWidget = new QWidget();
        stepWidget->setObjectName("stepIndicator");
        QVBoxLayout *stepLayout = new QVBoxLayout(stepWidget);
        stepLayout->setContentsMargins(10, 10, 10, 10);
        stepLayout->setSpacing(8);
        
        // === 创建图标 ===
        QLabel *iconLabel = new QLabel(m_stepIconTexts[i]);
        iconLabel->setObjectName("stepIcon");
        iconLabel->setAlignment(Qt::AlignCenter);
        iconLabel->setFixedSize(40, 40);
        
        // === 创建标题 ===
        QLabel *titleLabel = new QLabel(m_stepTitles[i]);
        titleLabel->setObjectName("stepTitle");
        titleLabel->setAlignment(Qt::AlignCenter);
        titleLabel->setWordWrap(true);
        
        stepLayout->addWidget(iconLabel);
        stepLayout->addWidget(titleLabel);
        
        // === 添加到列表 ===
        m_stepIndicators.append(stepWidget);
        m_stepLabels.append(titleLabel);
        m_stepIcons.append(iconLabel);
        
        m_stepsLayout->addWidget(stepWidget);
        
        // === 添加连接线（除了最后一个） ===
        if (i < m_stepTitles.size() - 1) {
            QLabel *connector = new QLabel("───");
            connector->setObjectName("stepConnector");
            connector->setAlignment(Qt::AlignCenter);
            m_stepsLayout->addWidget(connector);
        }
    }
    
    m_mainLayout->addWidget(m_stepsWidget);
}

/**
 * @brief 设置进度区域
 */
void GameAuthProgressWidget::setupProgressArea()
{
    m_progressWidget = new QWidget();
    m_progressLayout = new QVBoxLayout(m_progressWidget);
    m_progressLayout->setContentsMargins(20, 20, 20, 20);
    m_progressLayout->setSpacing(15);
    
    // === 进度条 ===
    m_progressBar = new QProgressBar();
    m_progressBar->setObjectName("authProgressBar");
    m_progressBar->setMinimum(0);
    m_progressBar->setMaximum(100);
    m_progressBar->setValue(0);
    m_progressBar->setTextVisible(true);
    m_progressBar->setFixedHeight(25);
    
    // === 状态标签 ===
    m_statusLabel = new QLabel("准备开始认证...");
    m_statusLabel->setObjectName("authStatus");
    m_statusLabel->setAlignment(Qt::AlignCenter);
    
    // === 详细信息标签 ===
    m_detailLabel = new QLabel("");
    m_detailLabel->setObjectName("authDetail");
    m_detailLabel->setAlignment(Qt::AlignCenter);
    m_detailLabel->setWordWrap(true);
    
    m_progressLayout->addWidget(m_progressBar);
    m_progressLayout->addWidget(m_statusLabel);
    m_progressLayout->addWidget(m_detailLabel);
    
    m_mainLayout->addWidget(m_progressWidget);
}

/**
 * @brief 设置操作按钮
 */
void GameAuthProgressWidget::setupActionButtons()
{
    m_buttonWidget = new QWidget();
    m_buttonLayout = new QHBoxLayout(m_buttonWidget);
    m_buttonLayout->setContentsMargins(20, 20, 20, 20);
    m_buttonLayout->setSpacing(15);
    
    m_buttonLayout->addStretch();
    
    // === 重试按钮 ===
    m_retryButton = new QPushButton("🔄 重试");
    m_retryButton->setObjectName("retryButton");
    m_retryButton->setVisible(false);
    m_retryButton->setMinimumWidth(100);
    connect(m_retryButton, &QPushButton::clicked, this, &GameAuthProgressWidget::onRetryClicked);
    m_buttonLayout->addWidget(m_retryButton);
    
    // === 取消按钮 ===
    m_cancelButton = new QPushButton("❌ 取消");
    m_cancelButton->setObjectName("cancelButton");
    m_cancelButton->setMinimumWidth(100);
    connect(m_cancelButton, &QPushButton::clicked, this, &GameAuthProgressWidget::onCancelClicked);
    m_buttonLayout->addWidget(m_cancelButton);
    
    m_mainLayout->addWidget(m_buttonWidget);
}

/**
 * @brief 应用统一主题样式
 */
void GameAuthProgressWidget::applyUnifiedTheme()
{
    QString styleSheet = QString(R"(
        /* GameAuthProgressWidget主容器样式 */
        GameAuthProgressWidget {
            background: qlineargradient(x1:0, y1:0, x2:1, y2:1,
                stop:0 %1, stop:0.5 #34495E, stop:1 #2C3E50);
            color: %2;
            font-family: 'Microsoft YaHei', 'Segoe UI', Arial, sans-serif;
        }
        
        /* 标题样式 */
        #authTitle {
            color: %3;
            font-size: 28px;
            font-weight: bold;
            margin: 10px 0;
        }
        
        #authSubtitle {
            color: #BDC3C7;
            font-size: 16px;
            margin: 5px 0;
        }
        
        /* 步骤指示器样式 */
        #stepIndicator {
            background: qlineargradient(x1:0, y1:0, x2:0, y2:1,
                stop:0 rgba(44, 62, 80, 0.9), stop:1 rgba(52, 73, 94, 0.9));
            border: 2px solid rgba(74, 144, 226, 0.3);
            border-radius: 12px;
            margin: 5px;
            min-width: 100px;
        }
        
        #stepIndicator[active="true"] {
            border-color: %3;
            background: qlineargradient(x1:0, y1:0, x2:0, y2:1,
                stop:0 rgba(74, 144, 226, 0.2), stop:1 rgba(74, 144, 226, 0.1));
        }
        
        #stepIndicator[completed="true"] {
            border-color: %6;
            background: qlineargradient(x1:0, y1:0, x2:0, y2:1,
                stop:0 rgba(39, 174, 96, 0.2), stop:1 rgba(39, 174, 96, 0.1));
        }
        
        #stepIndicator[error="true"] {
            border-color: %5;
            background: qlineargradient(x1:0, y1:0, x2:0, y2:1,
                stop:0 rgba(231, 76, 60, 0.2), stop:1 rgba(231, 76, 60, 0.1));
        }
        
        #stepIcon {
            color: %2;
            font-size: 18px;
            font-weight: bold;
        }
        
        #stepTitle {
            color: %2;
            font-size: 12px;
            font-weight: 500;
        }
        
        #stepConnector {
            color: rgba(74, 144, 226, 0.5);
            font-size: 12px;
            margin: 0 5px;
        }
        
        /* 进度条样式 */
        #authProgressBar {
            border: 2px solid %3;
            border-radius: 12px;
            text-align: center;
            background-color: rgba(44, 62, 80, 0.9);
            color: %2;
            font-size: 14px;
            font-weight: bold;
        }
        
        #authProgressBar::chunk {
            background: qlineargradient(x1:0, y1:0, x2:1, y2:0,
                stop:0 %3, stop:1 #5DADE2);
            border-radius: 10px;
        }
        
        /* 状态标签样式 */
        #authStatus {
            color: %3;
            font-size: 18px;
            font-weight: bold;
            margin: 10px 0;
        }
        
        #authDetail {
            color: #BDC3C7;
            font-size: 14px;
            margin: 5px 0;
        }
        
        /* 按钮样式 */
        #retryButton {
            background: qlineargradient(x1:0, y1:0, x2:0, y2:1,
                stop:0 %3, stop:1 #3498DB);
            color: white;
            border: none;
            border-radius: 8px;
            padding: 12px 20px;
            font-size: 14px;
            font-weight: bold;
        }
        
        #retryButton:hover {
            background: qlineargradient(x1:0, y1:0, x2:0, y2:1,
                stop:0 #5DADE2, stop:1 #4A90E2);
        }
        
        #cancelButton {
            background: qlineargradient(x1:0, y1:0, x2:0, y2:1,
                stop:0 rgba(44, 62, 80, 0.9), stop:1 rgba(52, 73, 94, 0.9));
            color: %2;
            border: 2px solid #34495E;
            border-radius: 8px;
            padding: 12px 20px;
            font-size: 14px;
            font-weight: 500;
        }
        
        #cancelButton:hover {
            border-color: %5;
            color: %5;
        }
        
    )").arg(m_backgroundColor, m_textColor, m_primaryColor, m_secondaryColor, m_errorColor, m_successColor, m_warningColor);
    
    setStyleSheet(styleSheet);
}

/**
 * @brief 开始加载动画
 */
void GameAuthProgressWidget::startLoadingAnimation()
{
    if (!m_animationTimer->isActive()) {
        m_animationFrame = 0;
        m_animationTimer->start();
    }
}

/**
 * @brief 停止加载动画
 */
void GameAuthProgressWidget::stopLoadingAnimation()
{
    if (m_animationTimer->isActive()) {
        m_animationTimer->stop();
        
        // === 恢复原始图标 ===
        for (int i = 0; i < m_stepIcons.size() && i < m_stepIconTexts.size(); ++i) {
            if (i < m_stepIcons.size()) {
                m_stepIcons[i]->setText(m_stepIconTexts[i]);
            }
        }
    }
}

/**
 * @brief 播放步骤转换动画
 * @param step 目标步骤
 */
void GameAuthProgressWidget::animateStepTransition(AuthStep step)
{
    int stepIndex = static_cast<int>(step);
    
    // === 设置之前的步骤为完成状态 ===
    for (int i = 0; i < stepIndex && i < m_stepIndicators.size(); ++i) {
        setStepCompleted(i, true);
        setStepActive(i, false);
    }
    
    // === 设置当前步骤为活动状态 ===
    if (stepIndex < m_stepIndicators.size()) {
        setStepActive(stepIndex, true);
        setStepCompleted(stepIndex, false);
    }
    
    // === 清除后续步骤的状态 ===
    for (int i = stepIndex + 1; i < m_stepIndicators.size(); ++i) {
        setStepCompleted(i, false);
        setStepActive(i, false);
        setStepError(i, false);
    }
}

/**
 * @brief 更新步骤指示器
 * @param step 当前步骤
 */
void GameAuthProgressWidget::updateStepIndicator(AuthStep step)
{
    animateStepTransition(step);
    
    // === 特殊处理完成状态 ===
    if (step == Completed) {
        int stepIndex = static_cast<int>(step);
        if (stepIndex < m_stepIndicators.size()) {
            setStepCompleted(stepIndex, true);
            setStepActive(stepIndex, false);
        }
        
        // === 恢复所有图标 ===
        for (int i = 0; i < m_stepIcons.size() && i < m_stepIconTexts.size(); ++i) {
            if (i < m_stepIcons.size()) {
                m_stepIcons[i]->setText(m_stepIconTexts[i]);
            }
        }
    }
}

/**
 * @brief 设置步骤完成状态
 * @param stepIndex 步骤索引
 * @param completed 是否完成
 */
void GameAuthProgressWidget::setStepCompleted(int stepIndex, bool completed)
{
    if (stepIndex >= 0 && stepIndex < m_stepIndicators.size()) {
        m_stepIndicators[stepIndex]->setProperty("completed", completed);
        m_stepIndicators[stepIndex]->style()->unpolish(m_stepIndicators[stepIndex]);
        m_stepIndicators[stepIndex]->style()->polish(m_stepIndicators[stepIndex]);
        
        if (completed && stepIndex < m_stepIcons.size()) {
            m_stepIcons[stepIndex]->setText("✅");
        }
    }
}

/**
 * @brief 设置步骤活动状态
 * @param stepIndex 步骤索引
 * @param active 是否活动
 */
void GameAuthProgressWidget::setStepActive(int stepIndex, bool active)
{
    if (stepIndex >= 0 && stepIndex < m_stepIndicators.size()) {
        m_stepIndicators[stepIndex]->setProperty("active", active);
        m_stepIndicators[stepIndex]->style()->unpolish(m_stepIndicators[stepIndex]);
        m_stepIndicators[stepIndex]->style()->polish(m_stepIndicators[stepIndex]);
    }
}

/**
 * @brief 设置步骤错误状态
 * @param stepIndex 步骤索引
 * @param error 是否错误
 */
void GameAuthProgressWidget::setStepError(int stepIndex, bool error)
{
    if (stepIndex >= 0 && stepIndex < m_stepIndicators.size()) {
        m_stepIndicators[stepIndex]->setProperty("error", error);
        m_stepIndicators[stepIndex]->style()->unpolish(m_stepIndicators[stepIndex]);
        m_stepIndicators[stepIndex]->style()->polish(m_stepIndicators[stepIndex]);
        
        if (error && stepIndex < m_stepIcons.size()) {
            m_stepIcons[stepIndex]->setText("❌");
        }
    }
}
